feat: add swap_api FastAPI service for browser swaps (PR #1 of browser-swap roadmap)#311
Open
LandynDev wants to merge 2 commits into
Open
feat: add swap_api FastAPI service for browser swaps (PR #1 of browser-swap roadmap)#311LandynDev wants to merge 2 commits into
LandynDev wants to merge 2 commits into
Conversation
Stateless HTTP front-end for browser swaps — wraps the existing contract_client / commitments / dendrite_lite modules with the eight endpoints from docs/swap-api/browser-swap-spec.md §6. Holds no keys, no funds, no state; broadcasts SwapReserveSynapse / SwapConfirmSynapse to whitelisted validators and waits for on-chain quorum. POST /reserve guards expectedRate exactly against the live commitment; any drift returns 409 RateChanged so the UI can re-quote. Adds an async broadcast helper in dendrite_lite so FastAPI handlers don't have to manage their own event loop, and a pure rate_selection module that factors the CLI's miner-eligibility logic out of swap.py.
bt.Dendrite owns an aiohttp ClientSession that __del__ cannot close cleanly outside a running loop. Per-request instantiation in the async path was leaking sockets under sustained load. Wrap the call in 'async with' so the session is torn down with each broadcast. CLI's sync wrapper still goes through this path via its own event loop, behavior unchanged. Review surfaced in cross-repo review of feat/swap-api.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements PR #1 of the browser-swap roadmap: a stateless FastAPI service inside the `allways` package that wraps the existing CLI swap modules with HTTP for browser orchestration. Per spec docs/swap-api/browser-swap-spec.md §6 — one new service, zero contract / DB / das-allways changes.
Spec deviation
`POST /confirm` body adds `minerHotkey` alongside `requestHash`. The contract has no requestHash→miner index, and the browser already gets `minerHotkey` back from `POST /reserve`. Routes it directly into the `SwapConfirmSynapse.reservation_id` field the validators expect. `requestHash` is kept as a correlation field.
Implementation notes
Test plan
Roadmap
This is PR #1 of 4 in docs/swap-api/pr-roadmap.md. PR #2 (`allways-ui` Swap page) and PR #3 (`alw-utils` dev-env + E2E suite) both depend on this merging first.